//
//  HDIdContentView.swift
//  HuaDaoPeifu
//
//  Created by Erickson on 16/4/13.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import UIKit

protocol HDIdContentViewDelegate:class {
    func didSelectIdent(_ typeID:String,typeInfo:String)
}


class HDIdContentView: UIView {
    
    let idTypeTextField = HDLabelTextFieldView()
    let nameTextField = HDLabelTextFieldView()
    var delegate:HDIdContentViewDelegate?
    let idTypeView = HDIdentificationSubView()
    var bottomPromptView = UILabel()
    var typeID:String?
    var typeInfo:String?
    
    init() {
        super.init(frame: CGRect.zero)
        self.backgroundColor = UIColor(hex: 0xf8f8f8)
        self.backgroundColor = UIColor.white
        setupViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupViews() {
        
        let lab = UILabel()
        self.addSubview(lab)
        lab.text = "请选择证件类型"
        lab.textColor = CenterColor.registerIdHudColor
        lab.snp.makeConstraints { (make) in
            make.top.equalTo(20)
            make.left.equalTo(10)
            make.right.equalTo(self)
            make.height.equalTo(15)
        }
        
        self.addSubview(idTypeView)
        idTypeView.snp.makeConstraints { (make) in
            make.top.equalTo(lab.snp.bottom)
            make.left.right.equalTo(self)
            make.height.equalTo(160)
            
        }
        
        
        idTypeTextField.label.text = "证件号"
        idTypeTextField.textField.clearButtonMode = .whileEditing
        idTypeTextField.textField.placeholder = "请输入证件号"
        
        self.addSubview(idTypeTextField)
        idTypeTextField.snp.makeConstraints { (make) in
            make.top.equalTo(idTypeView.snp.bottom).offset(15)
            make.left.equalTo(-0.7)
            make.right.equalTo(0.7)
            make.height.equalTo(49)
        }
        
        
        
        nameTextField.label.text = "姓名"
        nameTextField.textField.clearButtonMode = .whileEditing
        nameTextField.textField.placeholder = "请输入您的姓名"

        self.addSubview(nameTextField)
        nameTextField.snp.makeConstraints { (make) in
            make.top.equalTo(idTypeTextField.snp.bottom).offset(10)
            make.left.equalTo(-0.7)
            make.right.equalTo(0.7)
            make.height.equalTo(49)
        }
        
        bottomPromptView.text = "请您务必完成身份验证，否则无法注册成功。"
        bottomPromptView.font = UIFont.systemFont(ofSize: 13)
        bottomPromptView.textColor = CenterColor.centerHomeCellColor
        self.addSubview(bottomPromptView)
        bottomPromptView.snp.makeConstraints { (make) in
            make.top.equalTo(nameTextField.snp.bottom).offset(10)
            make.left.equalTo(self).offset(15)
            make.right.equalTo(self)
            make.height.equalTo(15)
        }
        
        let idButton = HDNextStepButton(title: "身份验证")
        self.addSubview(idButton)
        idButton.snp.makeConstraints { (make) in
            make.top.equalTo(bottomPromptView.snp.bottom).offset(30)
            make.left.equalTo(self).offset(40)
            make.right.equalTo(self).offset(-40)
            make.height.equalTo(40)
        }
        idButton.addTarget(self, action: #selector(HDIdContentView.idAction), for: .touchUpInside)
        
        
    }
    
    
    func idAction() {
        
        if idTypeView.currentId == "0" {
            typeID = "0"
            typeInfo = "身份证"
            judgeAge()
        }else if idTypeView.currentId == "1" {
            typeID = "1"
            typeInfo = "护照"
        }else if idTypeView.currentId == "2" {
            typeID = "7"
            typeInfo = "出生证"
        }else if idTypeView.currentId == "3" {
            typeID = "11"
            typeInfo = "回乡证"
        }else if idTypeView.currentId == "4" {
            typeID = "8"
            typeInfo = "驾驶证"
        }else if idTypeView.currentId == "5" {
            typeID = "9"
            typeInfo = "工号"
        }else if idTypeView.currentId == "6" {
            typeID = "8"
            typeInfo = "港澳通行证"
        }else if idTypeView.currentId == "7" {
            typeID = "4"
            typeInfo = "户口本"
        }else if idTypeView.currentId == "8" {
            typeID = "2"
            typeInfo = "军官证"
        }else if idTypeView.currentId == "9" {
            typeID = "8"
            typeInfo = "台湾通行证"
        }
        delegate?.didSelectIdent(typeID!,typeInfo: typeInfo!)
    }
//MARK: 判断是否满18岁
    func judgeAge() {
        
    }
    
}
